package com.voxel.sense.infomsg.utils.marker.cluster.strategy;

import com.amap.api.maps.model.LatLng;
import com.example.com.common.utils.L;
import com.voxel.sense.infomsg.utils.cover.EntityConvertStrategy;
import com.voxel.sense.infomsg.utils.marker.cluster.data.ClusterItem;
import com.voxel.sense.infomsg.utils.marker.cluster.data.RegionItem;

import java.util.ArrayList;
import java.util.List;

import cyy.example.com.facotry.constants.Constants;
import cyy.example.com.facotry.model.api.response.FirmLocationEntity;

/**
 * Created by ChenYiYao on 2018/6/6.
 */
public class FirmBeanConvertStrategy implements EntityConvertStrategy<ClusterItem, FirmLocationEntity> {

    @Override
    public List<ClusterItem> convertEntity(List<FirmLocationEntity> list) {

        return convertEntity(list, "");
    }


    public List<ClusterItem> convertEntity(List<FirmLocationEntity> list, String type) {
        if (list != null) {
            List<ClusterItem> regionItems = new ArrayList<>();
            convertFirmTypeNor(list, regionItems, type);
            return regionItems;
        }
        return null;
    }

    private void convertFirmTypeNor(List<FirmLocationEntity> list, List<ClusterItem> regionItems, String type) {
        for (FirmLocationEntity bean : list) {
            try {
                double latitude = Double.parseDouble(bean.getLatitude());
                double longitude = Double.parseDouble(bean.getLongitude());
                RegionItem item;
                if (Constants.MARKER_TYPE_NO_INFO.equals(type)) {
                    item = new RegionItem(new LatLng(latitude, longitude), "", bean);
                } else {
                    item = new RegionItem(new LatLng(latitude, longitude), type, bean);

                }
                regionItems.add(item);
            } catch (Exception e) {
                L.d("--------------------------");
                L.d("错误数据：" + bean.toString());
                L.d("--------------------------");
                e.printStackTrace();
            }
        }
    }
}
